home *** CD-ROM | disk | FTP | other *** search
- /*****
- * CStatusBar.c
- * Status bar graph class by Joe Zobkiw
- *
- * This code is free and in the public domain, if you use it, please mention
- * so in your About Box. Do not distribute altered versions of this source but
- * feel free to mess with it in any way. This is just a quick hack but could be
- * useful.
- *
- * Suggestions or bugs: AFA Zobkiw @ America Online
- *
- * NOTE: CStatusBar requires the following files to be included in the project:
- * - OSChecks.c
- * - MacTraps
- * - oops
- *****/
-
- #include "CStatusBar.h"
- #include "ColorToolbox.h"
-
- /******************************************************************************
- * IStatusBar initializes the status bar.
- * dialog is a DialogPtr to the dialog that the bar is in
- * item is the item number of the bar (usually a user item)
- * vertical is TRUE if the bar is vertically oriented
- * shadow is TRUE if we want a drop shadow
- * color is TRUE is we want to define a fill color
- * rgb is the fill color, ignored if (color == FALSE)
- *
- *****************************************************************************/
- void CStatusBar::IStatusBar( dialog, item, shadow, vertical, color, rgb )
-
- DialogPtr dialog;
- int item;
- Boolean shadow;
- Boolean vertical;
- Boolean color;
- RGBColor rgb;
- {
-
- this->dialog = dialog;
- this->item = item;
- this->shadow = shadow;
- this->vertical = vertical;
- this->color = color;
- this->rgb = rgb;
-
- Draw();
- }
-
- /******************************************************************************
- * Draw draws the outline of the status bar
- *
- *****************************************************************************/
- void CStatusBar::Draw( void )
- {
- GrafPtr oldPort;
- PenState pen;
- int itemType;
- Handle itemHandle;
- Rect itemRect;
-
- GetPort( &oldPort );
- GetPenState( &pen );
- SetPort( dialog );
- PenNormal();
-
- GetDItem( dialog, item, &itemType, &itemHandle, &itemRect );
- PenPat( white );
- PaintRect( &itemRect );
- PenPat( black );
- FrameRect( &itemRect );
-
- if (shadow) {
- MoveTo( itemRect.left + SHADOW_DEPTH, itemRect.bottom );
- LineTo( itemRect.right, itemRect.bottom );
- LineTo( itemRect.right, itemRect.top + SHADOW_DEPTH );
- }
-
- SetPort( oldPort );
- SetPenState( &pen );
- }
-
- /******************************************************************************
- * given a percentage of completion, Update will draw the status bar
- * filling either in color or in a gray pattern.
- *
- * repeated calls to Update with a larger percentage is how the bar is animated
- *
- *****************************************************************************/
- void CStatusBar::Update( percent )
- int percent;
- {
- Rect tempRect, myRect;
- GrafPtr oldPort;
- PenState pen;
- int itemType, rectLength, i, barFill;
- Handle itemHandle;
- Rect itemRect;
- RGBColor tempRgb;
-
- GetDItem( dialog, item, &itemType, &itemHandle, &itemRect );
- tempRect = itemRect;
-
- GetPort( &oldPort );
- GetPenState( &pen );
- SetPort( dialog );
- PenNormal();
-
- if ( ! this->vertical ) {
- rectLength = tempRect.right - tempRect.left;
- barFill = rectLength * .01 * percent;
- if ( (tempRect.left + barFill + 2) > (tempRect.right - 1) )
- barFill = tempRect.right - 2;
- else
- barFill = tempRect.left + barFill + 2;
- SetRect(&myRect,tempRect.left + 1, tempRect.top + 1,
- barFill, tempRect.bottom - 1);
- } else {
- rectLength = tempRect.bottom - tempRect.top;
- barFill = rectLength * .01 * percent;
- if ( (tempRect.bottom - barFill - 2) < (tempRect.top + 1) )
- barFill = tempRect.top + 2;
- else
- barFill = tempRect.bottom - barFill - 2;
- SetRect(&myRect,tempRect.left + 1, barFill,
- tempRect.right - 1, tempRect.bottom - 1);
- }
-
- if ( this->color )
- if ( ColorQDIsPresent() ) {
- tempRgb = rgb;
- RGBForeColor(&tempRgb);
- } else
- PenPat( gray );
- else
- PenPat ( gray );
-
- PaintRect(&myRect);
-
- if (color) {
- if ( ColorQDIsPresent() ) {
- tempRgb.red = 0;
- tempRgb.blue = 0;
- tempRgb.green = 0;
- RGBForeColor(&tempRgb);
- }
- }
-
- SetPort( oldPort );
- SetPenState( &pen );
- }